package com.computer.spring.framework.aop.aspect;

import com.computer.spring.framework.aop.advice.BYAdvice;
import com.computer.spring.framework.aop.intercept.BYMethodInterceptor;
import com.computer.spring.framework.aop.intercept.BYMethodInvocation;

import java.lang.reflect.Method;

/**
 * @Description
 * @Author MagicIce
 * @Date 2020/11/23 8:43
 */
public class BYAfterThrowingAdvice extends BYAbstractAspectJAdvice implements BYAdvice, BYMethodInterceptor {

    private String throwingName;
    private BYMethodInvocation methodInvocation;

    public BYAfterThrowingAdvice(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    public void setThrowingName(String throwingName) {
        this.throwingName = throwingName;
    }

    @Override
    public Object invoke(BYMethodInvocation methodInvocation) throws Throwable {
        try {
            return methodInvocation.proceed();
        } catch (Throwable throwable) {
            invokeAdviceMethod(methodInvocation, null, throwable.getCause());
            throw throwable;
        }
    }
}
